{% extends 'personInfoBase.html' %}
{% block personInfoContentRight %}
<style>
    .uploadsecretform{
        background: #fff;
        width: 800px;
        margin: 0 auto;
    }
    .textarea-content{
        text-align:center;
        

    }
    .title-content{
        margin: 10 auto;
        /* background: #f1f2 */

    }
    .form-container{
        width: 80%;
        margin: 0 auto;
        /* background: #ff1 */
   }
   .page-title{
	text-align: center;
   }
   #secretForm{
    margin: 10 auto;
    /* background: #f1f */

   }
</style>

<div class="uploadsecretform">
    <div class="form-group title-content">
        <h3 class='page-title'>绑定时间银行卡</h3>
    </div>
    <div class="form-container">
        <form  method="POST" id="secretForm">
            <div class="textarea-content form-group">
                <textarea cols="70" rows="20" id="textareaid" name="mydata" onchange="contentChange()" placeholder="把你将要绑定的时间银行卡的key粘贴到这里">
                </textarea>
            </div>
            <div class="form-group">
                <input disabled="disabled" type="button" value="上传" id="uploadButton" class="btn btn-primary " onclick="upload()">
                <span id="textareaTipid" style="color:red"></span>
            </div>
        </form>
   </div>
</div>
<script type="text/javascript">

function checksecretStr(keyStr){
    // alert(1);
    var data = keyStr
    if(data==""){
            // $('#textareaTipid').text("key不能为空");
            return false;
	}else {
        // alert(data)
        var flag = false
        $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                async:false,
                contentType : "application/json",
                dataType: "json",//从服务端返回的数据类型
                url: "/personInfo/uploadsecret/checksecret" ,//url
                data:JSON.stringify({ 'mydata':data}),
                success: function (result) {
                        //alert(result.message);//打印服务端返回的数据(调试用)
                        if(result.status== 500){
                            flag = true
                        }
                        else{
                            flag = false;
                        }
                },
                error:function(result){
                    flag = false
                }
            
            
                    

        });
        return flag
    }
			
}
function contentChange(){
    var data = $.trim($('#textareaid').val());
    if(checksecretStr(data)){
        $("#uploadButton").attr("disabled",false);
       $('#textareaTipid').text("");
    }else{
        $("#uploadButton").attr("disabled",true);
        $('#textareaTipid').text("时间银行卡key格式不正确，请检查!");

    }

}


function upload(){
    var data = $.trim($('#textareaid').val());
    if(!checksecretStr(data)){
        return
    }
    $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                async:false,
                contentType : "application/json",
                dataType: "json",//从服务端返回的数据类型
                url: "/personInfo/uploadsecret" ,//url
                data:JSON.stringify({ 'mydata':data}),
                success: function (result) {
                        if(result.status== 500){
                            window.location.href="/personInfo/accountlist";
                        }
                        else if(result.status== 501){
                            $("#uploadButton").attr("disabled",true);
                            $('#textareaTipid').text("该时间银行卡已经绑定过，请选择其它卡!");

                        }
                        else{
                            return false;
                        }
                },
                error:function(result){
                    return false
                }

            
            
                    

        });
}
    // document.onclick=function(){
    //     alert(1);
    //     // var str='5456455d4fgdfgdgdg \n dsfafdadfadfafa';
    //     // document.getElementById("textareaid").value=str;
    // }
</script>

{% endblock %}
